using System;
using System.Collections.Generic;
using TestCases.Utils.Formatters;

namespace TestCases.Utils
{
    public static class StringUtils
    {
        public static string FormatWith(this string format, Func<string, string> resolver)
        {
            return StringFormatter.FormatValue(format, resolver);
        }

        public static string FormatWith(this string format, IDictionary<string, object> dictionary)
        {
            return FormatWith(format, variableName => dictionary[variableName].ToSafeString());
        }

        public static string FormatWith(this string format, object properties)
        {
            return FormatWith(format, properties.ToDictionary());
        }
        
        public static string ToPlural(this string value)
        {
            return (value.EndsWith("y"))
                ? value.Substring(0, value.Length - 1) + "ies"
                : value + "s";
        }
        
    }
}